package visualization.jankenpon;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

import optimizers.ganeat.jankenpon.ConstantsJankenpon;

import fitness.EloResult;
import fitness.JankenponResult;

public class JankenponTournamentMatrix extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected JankenponResult result;

	public JankenponTournamentMatrix(JankenponResult fitnessResult){
		super();
		this.result = fitnessResult;
		this.setPreferredSize(new Dimension(200,20*fitnessResult.results.size()));
	}
	
	@Override
	public void paint(Graphics g){
		super.paint(g);
		int sizex = this.getWidth();
		int sizey = this.getHeight();
		int length = result.getDecomposition().length;
		for(int i=0;i<length;i++){
			for(int j=0; j< ConstantsJankenpon.rounds; j++){
				Color c = g.getColor();
				g.drawRect(j*sizex/ConstantsJankenpon.rounds, i*sizey/length, sizex/ConstantsJankenpon.rounds, sizey/length);
				g.setColor(result.results.get(i).iplayed[j] == ConstantsJankenpon.JAN? Color.BLUE : (result.results.get(i).iplayed[j] == ConstantsJankenpon.KEN ? Color.GREEN : Color.RED));
				if(result.results.get(i).iplayed[j] == -1)
					g.setColor(Color.WHITE);
				g.fillRect(j*sizex/ConstantsJankenpon.rounds+1, i*sizey/length+1, sizex/ConstantsJankenpon.rounds-2, sizey/length-2);
				g.setColor(result.results.get(i).uplayed[j] == ConstantsJankenpon.JAN? Color.BLUE : (result.results.get(i).uplayed[j] == ConstantsJankenpon.KEN ? Color.GREEN : Color.RED));
				if(result.results.get(i).uplayed[j] == -1)
					g.setColor(Color.WHITE);
				g.fillPolygon(new int[]{j*sizex/ConstantsJankenpon.rounds+1,j*sizex/ConstantsJankenpon.rounds+1,(j+1)*sizex/ConstantsJankenpon.rounds-1}, new int[]{i*sizey/length+1,(i+1)*sizey/length-1,(i+1)*sizey/length-1}, 3);
				
				g.setColor(c);
			}
		}
	}
}
